import 'package:flutter/material.dart';
import 'package:lejiaxueche/config/colors.dart';
import './pages/signup/signup.dart';
import './pages/exam/exam.dart';
import './pages/me/me.dart';

class NavigationItem extends StatefulWidget {
  @override
  _NavigationItemState createState() => _NavigationItemState();
}

class _NavigationItemState extends State<NavigationItem> {
  int _currentIndex = 1;
  PageController pageController;
  List<Widget> pagesList = [];
  List<BottomNavigationBarItem> navList = [
    BottomNavigationBarItem(
      icon: Image.asset(
        'assets/navigation/enroll_nor.png',
        width: 28.0,
        height: 28.0
      ),
      activeIcon: Image.asset(
        'assets/navigation/enroll_active.png',
        width: 28.0,
        height: 28.0,
      ),
      title: Text('报名', style: TextStyle(fontSize: 12.0)),
      // unread: 10
    ),
    BottomNavigationBarItem(
      icon: Image.asset(
        'assets/navigation/teach_nor.png',
        width: 28.0,
        height: 28.0,
      ),
      activeIcon: Image.asset(
        'assets/navigation/teach_active.png',
        width: 28.0,
        height: 28.0,
      ),
      title: Text('考试', style: TextStyle(fontSize: 12.0)),
      // unread: 0
    ),
    BottomNavigationBarItem(
      icon: Image.asset(
        'assets/navigation/me_nor.png',
        width: 28.0,
        height: 28.0,
      ),
      activeIcon: Image.asset(
        'assets/navigation/me_active.png',
        width: 28.0,
        height: 28.0,
      ),
      title: Text('我的', style: TextStyle(fontSize: 12.0)),
      // unread: 0
    )
  ];

  @override
  void initState() {
    super.initState();
    pagesList = [
      SignupPage(),
      ExamPage(),
      MePage()
    ];
    pageController = PageController(initialPage: _currentIndex);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView.builder(
        itemBuilder: (BuildContext context, int index) {
          return pagesList[index];
        },
        itemCount: pagesList.length,
        physics: NeverScrollableScrollPhysics(),
        controller: pageController,
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        fixedColor: Color(AppColors.navTextActiveColor),
        currentIndex: _currentIndex,
        items: navList,
        onTap: (int index) {
          setState(() {
            _currentIndex = index; 
          });
          pageController.animateToPage(_currentIndex, curve: Curves.linear, duration: Duration(milliseconds: 10));
        },
      ),
    );
  }
}